<template>
	<el-dialog :visible.sync="visible" :modal-append-to-body="false" :title="keyLan['name']" class="demo-ruleForm">
		<exAddEdit ref="exAddEdit" v-model="model"></exAddEdit>

		<div slot="footer" class="dialog-footer">
			<el-button v-if="isAdd" @click="resetThisVal('model')">{{ comLan["btnReset"] }}</el-button>
			<el-button @click="close">{{ comLan["btnCancel"] }}</el-button>
			<el-button type="primary" @click="save" :loading="loading">{{ comLan["btnSave"] }}</el-button>
		</div>
	</el-dialog>
</template>

<script>
import common from "@/common/common.js";
import js from "./js.js";
import exAddEdit from "@/Auto/SysCustomer/SysCustomerAddEdit.vue";

export default {
	name: "SysCustomerAdd",
	components: {
		exAddEdit
	},
	props: {
		value: {
			type: Object,
			default: function () {
				return {};
			}
		}
	},
	mixins: [common.baseVM, js],
	data() {
		return {
			model: {
				SysCustomerID: 0,
				EnumSysCustomerType: null,
				HeaderUrl: null,
				SysCustomerName: null,
				Phone: null,
				BirthDay: new Date(),
				Pwd: null,
				EnumStatus: 1,
				IsDemo: false,
				Remark: null,
				SysEmployeeID: null,
				EnumSysCustomerSource: null,
				EnumSysCustomerIntention: null,
				CertSearch03Json: null,
				CertSearch02Json: null,
				CertSearchUpdateTime: new Date(),
				ReferrerID: null,
				EnumGender: null,
				Address: null,
				Company: null,
				Qualification: null,
			}
		}
	},
	methods: {
		init() { },

		show(scope) {
			this.loadBeforeValSuccess = false;
			this.resetVal("model");
			this.isAdd = scope == null || scope.row == null;
			if (this.isAdd) { //新建
				this.loadBeforeVal();
				this.visible = true;
				return;
			}
			var id = scope.row.SysCustomerID;
			this.get("api/SysCustomer/Get?id=" + id).then(data => {
				this.model = data.Result;
				this.visible = true;
			});
		},
		close() {
			this.visible = false;
		},
		save() {
			this.$refs.exAddEdit.formValidate('formModel', () => {
				var post = JSON.parse(JSON.stringify(this.model));
				this.loading = true;
				this.post('api/SysCustomer/Save', post).then(data => {
					this.showToast(data.Message, "success");
					this.loading = false;

					this.clearBeforeVal();
					this.close();

					this.$emit("success");

					if (this.isAdd && !!this.$listeners["input"]) {
						this.$emit("input", data.Result);
					}
				}).catch((error) => {
					this.loading = false;
				});
			});
		}
	}
}
</script>